package com.lgy.controller;

import com.lgy.product.common.DecreaseStockInput;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.List;

/**
 * @Author 李光耀
 * @Date 2019-05-08 10:45
 */
@RestController
@DefaultProperties(defaultFallback = "defaultFallback")
public class HystrixController {

    // @HystrixCommand(fallbackMethod = "fallback")
    // 超时配置
//    @HystrixCommand(commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
//    })
    @HystrixCommand
    @GetMapping("/getProductInfoList")
    public String getProductInfoList() {

        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.postForObject("http://127.0.0.1:8082/product/listForOrder"
                , Arrays.asList("157875196266160022"), String.class);
    }

    private String fallback() {
        return "太拥挤了, 请稍候再试~~";
    }

    private String defaultFallback() {
        return "默认提示: 太拥挤了, 请稍候再试~~";
    }
}
